<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>lwIP: Mailboxes</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">lwIP
   &#160;<span id="projectnumber">2.1.2</span>
   </div>
   <div id="projectbrief">Lightweight IP stack</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__sys__mbox.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Mailboxes<div class="ingroups"><a class="el" href="group__lwip.html">lwIP</a> &raquo; <a class="el" href="group__sys__layer.html">Porting (system abstraction layer)</a> &raquo; <a class="el" href="group__sys__os.html">OS abstraction layer</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gab9793f30642de06ce87827e9adbe30cc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#gab9793f30642de06ce87827e9adbe30cc">sys_mbox_new</a> (sys_mbox_t *mbox, int size)</td></tr>
<tr class="separator:gab9793f30642de06ce87827e9adbe30cc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9d068386a3c53dd01b8af99c3ef77555"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#ga9d068386a3c53dd01b8af99c3ef77555">sys_mbox_post</a> (sys_mbox_t *mbox, void *msg)</td></tr>
<tr class="separator:ga9d068386a3c53dd01b8af99c3ef77555"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa36345e48a49d67cbb0878cd4cbd2195"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#gaa36345e48a49d67cbb0878cd4cbd2195">sys_mbox_trypost</a> (sys_mbox_t *mbox, void *msg)</td></tr>
<tr class="separator:gaa36345e48a49d67cbb0878cd4cbd2195"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf677a6e76adb7650a3020fdb3cb8429a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#gaf677a6e76adb7650a3020fdb3cb8429a">sys_mbox_trypost_fromisr</a> (sys_mbox_t *mbox, void *msg)</td></tr>
<tr class="separator:gaf677a6e76adb7650a3020fdb3cb8429a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga6464cd77cf6799bd8b3d6c840166a2e8"><td class="memItemLeft" align="right" valign="top">u32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#ga6464cd77cf6799bd8b3d6c840166a2e8">sys_arch_mbox_fetch</a> (sys_mbox_t *mbox, void **msg, u32_t timeout)</td></tr>
<tr class="separator:ga6464cd77cf6799bd8b3d6c840166a2e8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gafab441b130b4ec417012835dbe1e497c"><td class="memItemLeft" align="right" valign="top">u32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#gafab441b130b4ec417012835dbe1e497c">sys_arch_mbox_tryfetch</a> (sys_mbox_t *mbox, void **msg)</td></tr>
<tr class="separator:gafab441b130b4ec417012835dbe1e497c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac641a45812155d2234ef80dd6412882f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#gac641a45812155d2234ef80dd6412882f">sys_mbox_free</a> (sys_mbox_t *mbox)</td></tr>
<tr class="separator:gac641a45812155d2234ef80dd6412882f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8bcfab4bd791dd33f69a778e7585275d"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#ga8bcfab4bd791dd33f69a778e7585275d">sys_mbox_valid</a> (sys_mbox_t *mbox)</td></tr>
<tr class="separator:ga8bcfab4bd791dd33f69a778e7585275d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga53ddec9d7f5500c5b1d982cd17493172"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sys__mbox.html#ga53ddec9d7f5500c5b1d982cd17493172">sys_mbox_set_invalid</a> (sys_mbox_t *mbox)</td></tr>
<tr class="separator:ga53ddec9d7f5500c5b1d982cd17493172"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Mailboxes should be implemented as a queue which allows multiple messages to be posted (implementing as a rendez-vous point where only one message can be posted at a time can have a highly negative impact on performance). A message in a mailbox is just a pointer, nothing more. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga6464cd77cf6799bd8b3d6c840166a2e8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga6464cd77cf6799bd8b3d6c840166a2e8">&#9670;&nbsp;</a></span>sys_arch_mbox_fetch()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">u32_t sys_arch_mbox_fetch </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void **&#160;</td>
          <td class="paramname"><em>msg</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">u32_t&#160;</td>
          <td class="paramname"><em>timeout</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Blocks the thread until a message arrives in the mailbox, but does not block the thread longer than "timeout" milliseconds (similar to the <a class="el" href="group__sys__sem.html#ga8d364c5037778acb21c3df675db81b4f">sys_arch_sem_wait()</a> function). If "timeout" is 0, the thread should be blocked until a message arrives. The "msg" argument is a result parameter that is set by the function (i.e., by doing "*msg =
ptr"). The "msg" parameter maybe NULL to indicate that the message should be dropped. The return values are the same as for the <a class="el" href="group__sys__sem.html#ga8d364c5037778acb21c3df675db81b4f">sys_arch_sem_wait()</a> function: SYS_ARCH_TIMEOUT if there was a timeout, any other value if a messages is received.</p>
<p>Note that a function with a similar name, sys_mbox_fetch(), is implemented by lwIP.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to get a message from </td></tr>
    <tr><td class="paramname">msg</td><td>pointer where the message is stored </td></tr>
    <tr><td class="paramname">timeout</td><td>maximum time (in milliseconds) to wait for a message (0 = wait forever) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>SYS_ARCH_TIMEOUT on timeout, any other value if a message has been received </dd></dl>

</div>
</div>
<a id="gafab441b130b4ec417012835dbe1e497c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gafab441b130b4ec417012835dbe1e497c">&#9670;&nbsp;</a></span>sys_arch_mbox_tryfetch()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">u32_t sys_arch_mbox_tryfetch </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void **&#160;</td>
          <td class="paramname"><em>msg</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>This is similar to sys_arch_mbox_fetch, however if a message is not present in the mailbox, it immediately returns with the code SYS_MBOX_EMPTY. On success 0 is returned. To allow for efficient implementations, this can be defined as a function-like macro in sys_arch.h instead of a normal function. For example, a naive implementation could be: #define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) although this would introduce unnecessary delays.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to get a message from </td></tr>
    <tr><td class="paramname">msg</td><td>pointer where the message is stored </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 (milliseconds) if a message has been received or SYS_MBOX_EMPTY if the mailbox is empty </dd></dl>

</div>
</div>
<a id="gac641a45812155d2234ef80dd6412882f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac641a45812155d2234ef80dd6412882f">&#9670;&nbsp;</a></span>sys_mbox_free()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_mbox_free </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Deallocates a mailbox. If there are messages still present in the mailbox when the mailbox is deallocated, it is an indication of a programming error in lwIP and the developer should be notified.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to delete </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gab9793f30642de06ce87827e9adbe30cc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab9793f30642de06ce87827e9adbe30cc">&#9670;&nbsp;</a></span>sys_mbox_new()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a> sys_mbox_new </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Creates an empty mailbox for maximum "size" elements. Elements stored in mailboxes are pointers. You have to define macros "_MBOX_SIZE" in your lwipopts.h, or ignore this parameter in your implementation and use a default size. If the mailbox has been created, ERR_OK should be returned. Returning any other error will provide a hint what went wrong, but except for assertions, no real error handling is implemented.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>pointer to the mbox to create </td></tr>
    <tr><td class="paramname">size</td><td>(minimum) number of messages in this mbox </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>ERR_OK if successful, another err_t otherwise </dd></dl>

</div>
</div>
<a id="ga9d068386a3c53dd01b8af99c3ef77555"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga9d068386a3c53dd01b8af99c3ef77555">&#9670;&nbsp;</a></span>sys_mbox_post()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_mbox_post </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>msg</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Post a message to an mbox - may not fail -&gt; blocks if full, only to be used from tasks NOT from ISR!</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to posts the message </td></tr>
    <tr><td class="paramname">msg</td><td>message to post (ATTENTION: can be NULL) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga53ddec9d7f5500c5b1d982cd17493172"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga53ddec9d7f5500c5b1d982cd17493172">&#9670;&nbsp;</a></span>sys_mbox_set_invalid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sys_mbox_set_invalid </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Invalidate a mailbox so that <a class="el" href="group__sys__mbox.html#ga8bcfab4bd791dd33f69a778e7585275d">sys_mbox_valid()</a> returns 0. ATTENTION: This does NOT mean that the mailbox shall be deallocated: <a class="el" href="group__sys__mbox.html#gac641a45812155d2234ef80dd6412882f">sys_mbox_free()</a> is always called before calling this function! This may also be a define, in which case the function is not prototyped. </p>

</div>
</div>
<a id="gaa36345e48a49d67cbb0878cd4cbd2195"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa36345e48a49d67cbb0878cd4cbd2195">&#9670;&nbsp;</a></span>sys_mbox_trypost()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a> sys_mbox_trypost </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>msg</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Try to post a message to an mbox - may fail if full. Can be used from ISR (if the sys arch layer allows this). Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to posts the message </td></tr>
    <tr><td class="paramname">msg</td><td>message to post (ATTENTION: can be NULL) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gaf677a6e76adb7650a3020fdb3cb8429a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf677a6e76adb7650a3020fdb3cb8429a">&#9670;&nbsp;</a></span>sys_mbox_trypost_fromisr()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__infrastructure__errors.html#gaf02d9da80fd66b4f986d2c53d7231ddb">err_t</a> sys_mbox_trypost_fromisr </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>msg</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Try to post a message to an mbox - may fail if full. To be be used from ISR. Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mbox</td><td>mbox to posts the message </td></tr>
    <tr><td class="paramname">msg</td><td>message to post (ATTENTION: can be NULL) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ga8bcfab4bd791dd33f69a778e7585275d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga8bcfab4bd791dd33f69a778e7585275d">&#9670;&nbsp;</a></span>sys_mbox_valid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int sys_mbox_valid </td>
          <td>(</td>
          <td class="paramtype">sys_mbox_t *&#160;</td>
          <td class="paramname"><em>mbox</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns 1 if the mailbox is valid, 0 if it is not valid. When using pointers, a simple way is to check the pointer for != NULL. When directly using OS structures, implementing this may be more complex. This may also be a define, in which case the function is not prototyped. </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
